


#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include <wx/wfstream.h>

#include "wx/pdfdoc.h"



class PdfTuto3 : public wxPdfDocument
{
public:
  void SetMyTitle(const wxString& title)
  {
    m_myTitle = title;
    SetTitle(title);
  }

  void Header()
  {
   
    SetFont(wxT("Helvetica"),wxT("B"),15);
   
    double w = GetStringWidth(m_myTitle)+6;
    SetX((210-w)/2);
   
    SetDrawColour(wxColour(0,80,180));
    SetFillColour(wxColour(230,230,0));
    SetTextColour(wxColour(220,50,50));
   
    SetLineWidth(1);
   
    Cell(w,9,m_myTitle,wxPDF_BORDER_FRAME,1,wxPDF_ALIGN_CENTER,1);
   
    Ln(10);
  }

  void Footer()
  {
   
    SetY(-15);
   
    SetFont(wxT("Helvetica"),wxT("I"),8);
   
    SetTextColour(128);
   
    Cell(0,10,wxString::Format(wxT("Page %d"),PageNo()),0,0,wxPDF_ALIGN_CENTER);
  }

  void ChapterTitle(int num, const wxString& label)
  {
   
    SetFont(wxT("Helvetica"),wxT(""),12);
   
    SetFillColour(wxColour(200,220,255));
   
    Cell(0,6,wxString::Format(wxT("Chapter %d : "),num) + label,0,1,wxPDF_ALIGN_LEFT,1);
   
    Ln(4);
  }

  void ChapterBody(const wxString& file)
  {
   
    wxFileInputStream f(file);
    int len = f.GetLength();
    char* ctxt = new char[len+1];
    f.Read(ctxt,len);
    ctxt[len] = '\0';
    wxString txt(ctxt,*wxConvCurrent);
   
    SetFont(wxT("Times"),wxT(""),12);
   
    MultiCell(0,5,txt);
   
    Ln();
   
    SetFont(wxT(""),wxT("I"));
    Cell(0,5,wxT("(end of excerpt)"));
    delete [] ctxt;
  }

  void PrintChapter(int num, const wxString& title, const wxString& file)
  {
    AddPage();
    ChapterTitle(num,title);
    ChapterBody(file);
  }

  wxString m_myTitle;
};

void
tutorial3() {
  PdfTuto3 pdf;
  pdf.SetMyTitle(wxT("20000 Leagues Under the Seas"));
  pdf.SetAuthor(wxT("Jules Verne"));
  pdf.PrintChapter(1,wxT("A RUNAWAY REEF"),wxT("20k_c1.txt"));
  pdf.PrintChapter(2,wxT("THE PROS AND CONS"),wxT("20k_c2.txt"));
  pdf.SaveAsFile(wxT("tutorial3.pdf"));
} 

